home *** CD-ROM | disk | FTP | other *** search
- {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- (c) TechInsite Pty. Ltd.
- PO Box 429, Abbotsford, Melbourne. 3067 Australia
- Phone: +61 3 9419 6456
- Fax: +61 3 9419 1682
- Web: www.techinsite.com.au
- EMail: peter_hinrichsen@techinsite.com.au
-
- Created: Jan 2000
-
- Notes: Family of visitors to manage mapping of
- address book classes to Interbase
-
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
- unit Adrs_Srv;
-
- interface
- uses
- tiPtnVisitorDB
- ;
-
- type
-
- // Read the primary keys of all the people in the database
- //----------------------------------------------------------------------------
- TVisPersonRead_PK = class( TVisDBSelect )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure MapRowsToObject ; override ;
- end ;
-
- // Read the details of one person
- //----------------------------------------------------------------------------
- TVisPersonRead_Detail = class( TVisDBSelect )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure MapRowsToObject ; override ;
- end ;
-
- // Update a person
- //----------------------------------------------------------------------------
- TVisPersonUpdate = class( TVisDBUpdate )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- // Delete a person
- //----------------------------------------------------------------------------
- TVisPersonDelete = class( TVisDBUpdate )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- // Insert a new person
- //----------------------------------------------------------------------------
- TVisPersonCreate = class( TVisDBUpdate )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- // Read all the address(es) for a person
- //----------------------------------------------------------------------------
- TVisAdrsRead = class( TVisDBSelect )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure MapRowsToObject ; override ;
- end ;
-
- // Read all the EAddress(es) for a person
- //----------------------------------------------------------------------------
- TVisEAdrsRead = class( TVisDBSelect )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure MapRowsToObject ; override ;
- end ;
-
- // Insert a new EAddress
- //----------------------------------------------------------------------------
- TVisEAdrsCreate = class( TVisDBUpdate )
- private
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- // Update an existing EAddress
- //----------------------------------------------------------------------------
- TVisEAdrsUpdate = class( TVisDBUpdate )
- private
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- // Delete an EAddress
- //----------------------------------------------------------------------------
- TVisEAdrsDelete = class( TVisDBUpdate )
- private
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- // Insert a new address
- //----------------------------------------------------------------------------
- TVisAdrsCreate = class( TVisDBUpdate )
- private
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- //----------------------------------------------------------------------------
- TVisAdrsUpdate = class( TVisDBUpdate )
- private
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
- //----------------------------------------------------------------------------
- TVisAdrsDelete = class( TVisDBUpdate )
- private
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure SetupParams ; override ;
- procedure UpdateObject ; override ;
- end ;
-
-
- implementation
- uses
- Adrs_BOM
- ,tiPtnVisitorMgr
- ,tiPtnVisitor
- ,tiPerObjAbs
- ,cAdrs
- ,cSQL
- ,tiUtils
- ;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisPersonRead
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisPersonRead_PK.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPersonList ) ;
- end;
-
- procedure TVisPersonRead_PK.Init;
- begin
- Query.SQL.Text := cSQLPersonRead_PK ;
- end;
-
- procedure TVisPersonRead_PK.MapRowsToObject;
- var
- lData : TPerson ;
- begin
- lData := TPerson.Create ;
- lData.OID := Query.FieldByName( 'OID' ).AsInteger ;
- lData.LastName := Query.FieldByName( 'Last_Name' ).AsString ;
- lData.FirstName := Query.FieldByName( 'First_Name' ).AsString ;
- lData.ObjectState := posPK ;
- TVisList( Visited ).Add( lData ) ;
- end ;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisAdrsRead
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisAdrsRead.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPerson ) and
- ( TPerson( Visited ).ObjectState = posPK ) ;
-
- end;
-
- procedure TVisAdrsRead.Init;
- begin
- Query.SQL.Text := cSQLPersonAddressRead ;
- end;
-
- procedure TVisAdrsRead.MapRowsToObject;
- var
- lData : TAddress ;
- begin
- lData := TAddress.Create ;
- lData.OID := Query.FieldByName( 'OID' ).AsInteger ;
- lData.AdrsType := Query.FieldByName( 'Adrs_Type' ).AsString ;
- lData.Lines := Query.FieldByName( 'Lines' ).AsString ;
- lData.State := Query.FieldByName( 'State' ).AsString ;
- lData.PCode := Query.FieldByName( 'PCode' ).AsString ;
- lData.Country := Query.FieldByName( 'Country' ).AsString ;
- lData.Owner := TPerson( Visited ) ;
- TPerson( Visited ).AddressList.Add( lData ) ;
- end;
-
- procedure TVisAdrsRead.SetupParams;
- begin
- TPerson( Visited ).AddressList.Clear ;
- Query.ParamByName( 'owner_oid' ).AsInteger := TPerson( Visited ).OID ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisEAdrsRead
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisEAdrsRead.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPerson ) and
- ( TPerson( Visited ).ObjectState = posPK ) ;
- end;
-
- procedure TVisEAdrsRead.Init;
- begin
- Query.SQL.Text := cSQLPersonEAddressRead ;
- end;
-
- procedure TVisEAdrsRead.MapRowsToObject;
- var
- lData : TEAddress ;
- begin
- lData := TEAddress.Create ;
- lData.OID := Query.FieldByName( 'OID' ).AsInteger ;
- lData.EAdrsType := Query.FieldByName( 'EAdrs_Type' ).AsString ;
- lData.Text := Query.FieldByName( 'Text' ).AsString ;
- lData.Owner := TPerson( Visited );
- TPerson( Visited ).EAddressList.Add( lData ) ;
- end;
-
- procedure TVisEAdrsRead.SetupParams;
- begin
- TPerson( Visited ).EAddressList.Clear ;
- Query.ParamByName( 'owner_oid' ).AsInteger := TPerson( Visited ).OID ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisPersonRead_Detail
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisPersonRead_Detail.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPerson ) and
- ( TPerObjAbs( Visited ).ObjectState = posPK ) ;
- end;
-
- // -----------------------------------------------------------------------------
- procedure TVisPersonRead_Detail.Init;
- begin
- Query.SQL.Text := cSQLPersonRead_Detail ;
- end;
-
- // -----------------------------------------------------------------------------
- procedure TVisPersonRead_Detail.MapRowsToObject;
- begin
- with Visited as TPerson do begin
- Title := Query.FieldByName( 'Title' ).AsString ;
- Initials := Query.FieldByName( 'Initials' ).AsString ;
- Notes := Query.FieldByName( 'Notes' ).AsString ;
- ObjectState := posClean ;
- end ;
- end;
-
- // -----------------------------------------------------------------------------
- procedure TVisPersonRead_Detail.SetupParams;
- begin
- Query.ParamByName( 'OID' ).AsInteger := TPerson( Visited ).OID ;
- end ;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisPersonUpate
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisPersonUpdate.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPerson ) and
- ( TPerson( Visited ).ObjectState = posUpdate ) ;
- end;
-
- procedure TVisPersonUpdate.Init;
- begin
- Query.SQL.Text := cSQLPersonUpdate ;
- end;
-
- procedure TVisPersonUpdate.SetupParams;
- begin
- Query.ParamByName( 'OID' ).AsInteger := TPerson( Visited ).OID ;
- Query.ParamByName( 'First_Name' ).AsString := TPerson( Visited ).FirstName ;
- Query.ParamByName( 'Last_Name' ).AsString := TPerson( Visited ).LastName ;
- Query.ParamByName( 'Title' ).AsString := TPerson( Visited ).Title ;
- Query.ParamByName( 'Initials' ).AsString := TPerson( Visited ).Initials ;
- Query.ParamByName( 'Notes' ).AsString := TPerson( Visited ).Notes ;
- end;
-
- procedure TVisPersonUpdate.UpdateObject;
- begin
- TPerson( Visited ).ObjectState := posClean ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisPersonDelete
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisPersonDelete.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPerson ) and
- ( TPerson( Visited ).ObjectState = posDelete ) ;
- end;
-
- procedure TVisPersonDelete.Init;
- begin
- Query.SQL.Text := cSQLPersonDelete ;
- end;
-
- procedure TVisPersonDelete.SetupParams;
- begin
- Query.ParamByName( 'OID' ).AsInteger := TPerson( Visited ).OID ;
- end;
-
- procedure TVisPersonDelete.UpdateObject;
- begin
- TPerson( Visited ).ObjectState := posClean ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisPersonCreate
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisPersonCreate.AcceptVisitor: boolean;
- begin
- result := ( Visited is TPerson ) and
- ( TPerson( Visited ).ObjectState = posCreate ) ;
- end;
-
- procedure TVisPersonCreate.Init;
- begin
- Query.SQL.Text := cSQLPersonCreate ;
- end;
-
- procedure TVisPersonCreate.SetupParams;
- begin
- Query.ParamByName( 'OID' ).AsInteger := TPerson( Visited ).OID ;
- Query.ParamByName( 'First_Name' ).AsString := TPerson( Visited ).FirstName ;
- Query.ParamByName( 'Last_Name' ).AsString := TPerson( Visited ).LastName ;
- Query.ParamByName( 'Title' ).AsString := TPerson( Visited ).Title ;
- Query.ParamByName( 'Initials' ).AsString := TPerson( Visited ).Initials ;
- Query.ParamByName( 'Notes' ).AsString := TPerson( Visited ).Notes ;
- end;
-
- procedure TVisPersonCreate.UpdateObject;
- begin
- TPerson( Visited ).ObjectState := posClean ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisEAdrsCreate
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisEAdrsCreate.AcceptVisitor: boolean;
- begin
- result := ( Visited is TEAddress ) and
- ( TEAddress( Visited ).ObjectState = posCreate ) ;
- end;
-
- procedure TVisEAdrsCreate.Init;
- begin
- Query.SQL.Text := cSQLPersonEAddressCreate ;
- end;
-
- procedure TVisEAdrsCreate.SetupParams;
- begin
- with Visited as TEAddress do begin
- Query.ParamByName( 'OID' ).AsInteger := OID ;
- Query.ParamByName( 'Owner_OID' ).AsInteger := Owner.OID ;
- Query.ParamByName( 'EAdrs_Type' ).AsString := EAdrsType ;
- Query.ParamByName( 'Text' ).AsString := Text ;
- end ;
- end;
-
- procedure TVisEAdrsCreate.UpdateObject ;
- begin
- TEAddress( Visited ).ObjectState := posClean ;
- end ;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisEAdrsDelete
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisEAdrsDelete.AcceptVisitor: boolean;
- begin
- result := ( Visited is TEAddress ) and
- ( TEAddress( Visited ).ObjectState = posDelete ) ;
- end;
-
- //------------------------------------------------------------------------------
- procedure TVisEAdrsDelete.Init;
- begin
- Query.SQL.Text := cSQLPersonEAddressDelete ;
- end;
-
- //------------------------------------------------------------------------------
- procedure TVisEAdrsDelete.SetupParams;
- begin
- Query.ParamByName( 'OID' ).AsInteger := TEAddress( Visited ).OID ;
- end;
-
- //------------------------------------------------------------------------------
- procedure TVisEAdrsDelete.UpdateObject;
- begin
- TEAddress( Visited ).ObjectState := posDeleted ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisEAdrsUpdate
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisEAdrsUpdate.AcceptVisitor: boolean;
- begin
- result := ( Visited is TEAddress ) and
- ( TEAddress( Visited ).ObjectState = posUpdate ) ;
- end;
-
- procedure TVisEAdrsUpdate.Init;
- begin
- Query.SQL.Text := cSQLPersonEAddressUpdate ;
- end;
-
- procedure TVisEAdrsUpdate.SetupParams;
- begin
- with Visited as TEAddress do begin
- Query.ParamByName( 'OID' ).AsInteger := OID ;
- Query.ParamByName( 'Owner_OID' ).AsInteger := Owner.OID ;
- Query.ParamByName( 'EAdrs_Type' ).AsString := EAdrsType ;
- Query.ParamByName( 'Text' ).AsString := Text ;
- end ;
- end;
-
- procedure TVisEAdrsUpdate.UpdateObject;
- begin
- TEAddress( Visited ).ObjectState := posClean ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisAdrsCreate
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisAdrsCreate.AcceptVisitor: boolean;
- begin
- result := ( Visited is TAddress ) and
- ( TEAddress( Visited ).ObjectState = posCreate ) ;
- end;
-
- procedure TVisAdrsCreate.Init;
- begin
- Query.SQL.Text := cSQLPersonAddressCreate ;
- end ;
-
- procedure TVisAdrsCreate.SetupParams;
- begin
- with Visited as TAddress do begin
- Query.ParamByName( 'oid' ).AsInteger := OID ;
- Query.ParamByName( 'owner_oid' ).AsInteger := Owner.OID ;
- Query.ParamByName( 'adrs_type' ).AsString := AdrsType ;
- Query.ParamByName( 'lines' ).AsString := Lines ;
- Query.ParamByName( 'state' ).AsString := State ;
- Query.ParamByName( 'pcode' ).AsString := PCode ;
- Query.ParamByName( 'country' ).AsString := Country ;
- end ;
- end;
-
- procedure TVisAdrsCreate.UpdateObject;
- begin
- TAddress( Visited ).ObjectState := posClean ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisAdrsUpdate
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisAdrsUpdate.AcceptVisitor: boolean;
- begin
- result := ( Visited is TAddress ) and
- ( TEAddress( Visited ).ObjectState = posUpdate ) ;
- end;
-
- procedure TVisAdrsUpdate.Init;
- begin
- Query.SQL.Text := cSQLPersonAddressUpdate ;
- end;
-
- procedure TVisAdrsUpdate.SetupParams;
- begin
- with Visited as TAddress do begin
- Query.ParamByName( 'oid' ).AsInteger := OID ;
- Query.ParamByName( 'owner_oid' ).AsInteger := Owner.OID ;
- Query.ParamByName( 'adrs_type' ).AsString := AdrsType ;
- Query.ParamByName( 'lines' ).AsString := Lines ;
- Query.ParamByName( 'state' ).AsString := State ;
- Query.ParamByName( 'pcode' ).AsString := PCode ;
- Query.ParamByName( 'country' ).AsString := Country ;
- end ;
- end;
-
- procedure TVisAdrsUpdate.UpdateObject;
- begin
- TAddress( Visited ).ObjectState := posClean ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisAdrsDelete
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisAdrsDelete.AcceptVisitor: boolean;
- begin
- result := ( Visited is TAddress ) and
- ( TEAddress( Visited ).ObjectState = posDelete ) ;
- end;
-
- procedure TVisAdrsDelete.Init;
- begin
- Query.SQL.Text := cSQLPersonAddressDelete ;
- end;
-
- procedure TVisAdrsDelete.SetupParams;
- begin
- with Visited as TAddress do begin
- Query.ParamByName( 'oid' ).AsInteger := OID ;
- end ;
- end;
-
- procedure TVisAdrsDelete.UpdateObject;
- begin
- TAddress( Visited ).ObjectState := posDeleted ;
- end;
-
- initialization
- gVisitorCache.RegisterVisitor( cgsAdrs_Read_PK, TVisPersonRead_PK ) ;
-
- // The order of these is important as ObjectState is set to pkClean in
- // TVisPersonRead_Detail, and TVisAdrsRead and TVisEAdrsRead will only be
- // read if objectState = posPK
- gVisitorCache.RegisterVisitor( cgsAdrs_Read_Detail, TVisAdrsRead ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Read_Detail, TVisEAdrsRead ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Read_Detail, TVisPersonRead_Detail ) ;
-
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisPersonCreate ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisPersonUpdate ) ;
-
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisEAdrsUpdate ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisEAdrsCreate ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisEAdrsDelete ) ;
-
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisAdrsCreate ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisAdrsUpdate ) ;
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisAdrsDelete ) ;
-
- gVisitorCache.RegisterVisitor( cgsAdrs_Update, TVisPersonDelete ) ;
-
- end.
-